using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameSweet : MonoBehaviour
{
    private int x;
    private int y;
    private GameManager.SweetsType type;
    private MovedSweet movedComponent;

    [HideInInspector] //在属性面板上隐藏
    public GameManager gameManager;

    public int X
    {
        get => x;
        set
        {
            if (CanMove())
            {
                x = value;
            }
        }
    }

    public int Y
    {
        get => y;
        set
        {
            if (CanMove())
            {
                y = value;
            }
        }
    }

    public GameManager.SweetsType Type
    {
        get => type;
    }

    public MovedSweet MovedComponent
    {
        get => movedComponent;
    }

    public ColorSweet ColoredComponent
    {
        get => coloredComponent;
    }

    private ColorSweet coloredComponent;

    private void Awake()
    {
        movedComponent = GetComponent<MovedSweet>();
        coloredComponent = GetComponent<ColorSweet>();
    }

    public void Init(int _x, int _y, GameManager _gameManager, GameManager.SweetsType _type)
    {
        x = _x;
        y = _y;
        gameManager = _gameManager;
        type = _type;
    }

    public bool CanMove()
    {
        return movedComponent != null;
    }

    public bool CanColor()
    {
        return coloredComponent != null;
    }

    //鼠标的进入按下抬起
    private void OnMouseDown()
    {
        gameManager.PressSweet(this);
    }

    private void OnMouseEnter()
    {
        gameManager.EnterSweet(this);
    }


    private void OnMouseUp()
    {
        gameManager.ReleaseSweet();
    }
}